package com.yozinga.service;

import android.content.Intent;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.util.Log;

import com.yozinga.http.HttpRequestCaller;
import com.yozinga.http.HttpRequestCaller.ServiceResponse;

public class YozingaService extends MultiThreadService {

	private static final int MAX_THREADS = 1;
	public static final String INTENT_EXTRA_RECEIVER = "intentReceiver";
	
	public YozingaService() {
		super(MAX_THREADS);
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		String url = intent.getStringExtra("url");
		String id = intent.getStringExtra("id");
		int method = intent.getIntExtra("method",HttpRequestCaller.GET);
		String action = intent.getStringExtra("action");
		Bundle requestBody = intent.getExtras();
		HttpRequestCaller httpRequestCaller = new HttpRequestCaller();
		ServiceResponse response = httpRequestCaller.GetServiceResponse(url,id, method, null, requestBody,action);
		
		Log.i("Today","Response COd eis:"+response.responseHttpStatusCode);
		//if(response.responseHttpStatusCode == 200 || response.responseHttpStatusCode == 201){
			Log.i("Today","Response COd eis:"+response.responseHttpStatusCode);
			ResultReceiver receiver = (ResultReceiver) intent
					.getParcelableExtra(INTENT_EXTRA_RECEIVER);
			Bundle data = new Bundle();
			data.putString("ServiceResponse", response.response);
			data.putString("action",action);
			if (receiver != null) {
				receiver.send(response.responseHttpStatusCode, data);
			}
		//}
	}
	
}
